package com.cheng.supre.customcalendarview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

/**
 * date: on 2018/2/2
 * time: 12:49
 * Projec_name: calendarview
 * Package_name: com.cheng.supre.customcalendarview
 * Author: MrT.Cheng
 * desc:
 */

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemViewHolder> {

    private Context context;
    private int item_width;
    private List<String> datas;

    public ItemAdapter(Context context, int item_width, List<String> datas) {
        this.context = context;
        this.item_width = item_width;
        this.datas = datas;
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(LayoutInflater.from(context).inflate(R.layout.rv_item,parent,false));
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {

        holder.itemView.setLayoutParams(new LinearLayout.LayoutParams(item_width, LinearLayout.LayoutParams.MATCH_PARENT));

        if (position == 0){
            holder.itemView.setBackgroundColor(context.getResources().getColor(R.color.item_first));
            holder.textView.setText("");
        }else {
            holder.itemView.setBackgroundColor(context.getResources().getColor(R.color.colorPrimaryDark));
            holder.textView.setText(datas.get(position));
        }

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder{

        TextView textView;
        public ItemViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv);
        }
    }
}
